import Cookie from 'js-cookie'
export default {
    state: {
        token: "",
        userData: {}
    },
    getters: {
        processedData: state => {
            // 在这里对原始数据进行处理，比如调用 slice 方法
            let data = state.userData[0].user_pic.slice(8)
            let newData = "http://127.0.0.1:3002/" + data
            return newData
        }
    },
    mutations: {
        setToken(state, val) {
            state.token = val
            Cookie.set('token', val)//把token加到cookie
        },
        clearToken(state) {
            state.token = ''
            Cookie.remove('token')//删除cookie中的token
        },
        getToken(state) {
            state.token = state.token || Cookie.get("token") //获取cookie中的token
        },
        setUserData(state, val) {
            state.userData = val
        },
        clearUserData(state) {
            state.userData = {}
        },
        getUserData(state) {
            state.userData = state.userData
        },
    }
}